package com.origin.app


import android.content.Intent

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings.Global
import android.util.Log


import android.view.View
import android.widget.Button
import com.origin.app.bean.ABean
import com.origin.app.bean.TestBean
import com.origin.app.bean.UserProtectionAddressBean
import com.origin.app.business.immersive.BuImmersiveActivity
import com.origin.app.business.net.NetActivity
import com.origin.app.greendao.AppDaoManager
import com.origin.baselibrary.devices.DevicesUtils
import com.origin.maplibrary.MapActivity
import com.origin.uilibrary.activity.UiActivity
import com.origin.utils.SharedPreferencesUtils
//import com.origin.opengles_ndk.OpenGLESActivity
import com.origin.utils.activity.FileUtilsActivity
import com.origin.utils.activity.PermissionsRequestActivity
import com.origin.utils.activity.ScreenAdaptationActivity
import com.origin.utils.log.LogUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.util.Calendar


class MainActivity : AppCompatActivity() {

    fun getMillisInFutureOfToday(timestamp: Long): Long {
        // 获取明天凌晨时间戳
        val calendar = Calendar.getInstance()
        calendar[calendar[Calendar.YEAR], calendar[Calendar.MONTH], calendar[Calendar.DAY_OF_MONTH] + 1, 0, 0] = 0
        val terminalTimestamp = calendar.timeInMillis
        return terminalTimestamp - timestamp
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.addBtn).text =
            (SharedPreferencesUtils.getParam(this, "key", 0) as Int).toString()

        val testBean = TestBean();
        val name = "${Math.random() * 1000}"
        val num = Math.random() * 1000
        testBean.name = name;
        testBean.num = num.toInt()

        AppDaoManager.addABean(ABean("${Math.random() * 1000}"))
        AppDaoManager.loadAList()

        // String address, double latitude,
        //                                     double longitude, boolean collect

        AppDaoManager.addUserAddressBean(UserProtectionAddressBean("${Math.random() * 1000}", 1.1, 1.2, true))
        AppDaoManager.loadUserAddressList()

        AppDaoManager.addBean(testBean)
        AppDaoManager.loadList()

        val time = getMillisInFutureOfToday(System.currentTimeMillis())
        LogUtils.__e("倒计时 ${time}")
    }

    fun  goOpenCvPage(view: View){
        startActivity(Intent(this, OpenCvPage::class.java))
    }
    fun goWebViewPage(view: View){
        startActivity(Intent(this, WebViewPage::class.java))
    }

    fun goShadowLayoutPage(view: View) {
        startActivity(Intent(this, ShadowLayoutActivity::class.java))
    }

    fun goPermissionsRequestPage(view: View) {
        startActivity(Intent(this, PermissionsRequestActivity::class.java))
    }

    fun blueToothClick(view: View) {
    }

    fun testClick(view: View) {

//        LogUtils._e("123", isSaveLog = true)
    }

    fun goNetPage(view: View) {
        startActivity(Intent(this, NetActivity::class.java))
    }

    fun goFloatWindowPage(view: View) {
        startActivity(Intent(this, FloatWindowActivity::class.java))
    }

    fun getIMEI(view: View){
        GlobalScope.launch(context = Dispatchers.Main) {

            var str=  DevicesUtils.getImei(this@MainActivity)
            Log.e("获取iemi",str)
        }
    }
    fun goTextUtilsPage(view: View) {
        startActivity(Intent(this, TextUtilsActivity::class.java))
    }

    fun goOpenGLESPage(view: View) {
//        startActivity(Intent(this, OpenGLESActivity::class.java))
    }

    fun goFileUtilsPage(view: View) {
        startActivity(Intent(this, FileUtilsActivity::class.java))
    }

    fun goAIDLPage(view: View) {
    }

    fun goMapPage(view: View) {
        startActivity(Intent(this, MapActivity::class.java))
    }

    fun goScreenAdaptationPage(view: View) {
        startActivity(Intent(this, ScreenAdaptationActivity::class.java))
    }

    fun goUIPage(view: View) {
//        startActivity(Intent(this, UiActivity::class.java))
        startActivity(Intent(this, ParallaxPageActivity::class.java))
    }

    fun goImmersivePage(view: View) {
        startActivity(Intent(this, BuImmersiveActivity::class.java))
    }

    fun goFilePickerPage(view: View) {
        startActivity(Intent(this, FilePickerDemoActivity::class.java))
    }

    fun addFun(view: View) {
        var num = SharedPreferencesUtils.getParam(this, "key", 0) as Int
        num = num + 1;
        findViewById<Button>(R.id.addBtn).text =
            num.toString()
        SharedPreferencesUtils.setParam(this, "key", num)
    }


}
